using System;
using Scenario.WorkflowEngine.DataModel;

namespace Scenario.WorkflowEngine.DataModel.WorkflowDataTypes
{
	//*********************************************************************
	//
	// DataTypeValue Class
	//
	// The XmlDataTypeValue class represents one of possible values to assign
	// to an application result or to a script result or to a subflow exit task
	//
	//*********************************************************************

	public class XMLDataTypeValue : bOS.XML.Data.XMLObject
	{
		public const string MAIN_NODE				= "Value";

		private const string KEY_ATTRIBUTE			= "Key";

		/** FIELDS **/

		private string sKey;
		private string sValue;

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Width simple Property **/
		public XMLDataTypeValue()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width xml parsering**/
		public XMLDataTypeValue(System.Xml.XmlNode node)
		{
			Parse(node);
		}

		/** PROPERTIES **/


		public string Key 
		{
			get { return sKey; }
			set { sKey = value; }
		}

		public string Value 
		{
			get { return sValue; }
			set { sValue = value; }
		}


		/** INSTANCE METHODS **/

		/** Inizializing method **/
		override public void Init()
		{
			sKey= string.Empty;
			sValue= string.Empty;
		}

		/** Parsering method for filling the value **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count; i++)
			{
				node= node2Parse.Attributes.Item(i);

				switch (node.Name)
				{
					case XMLDataTypeValue.KEY_ATTRIBUTE:
						sKey = node.InnerText;
						break;
				}
			}

			/** fill tag value **/
			sValue = node2Parse.InnerXml;
					 
		}

		override public bOS.XML.XMLNode GetXMLNode()
		{
			bOS.XML.XMLNode xmlNode = new bOS.XML.XMLNode(XMLDataTypeValue.MAIN_NODE);
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute ( XMLDataTypeValue.KEY_ATTRIBUTE, sKey) );

			xmlNode.SetValue (sValue);
			
			return xmlNode;
		}

		/** STATIC METHODS **/

		/** no static methods **/
	}
}